<script setup lang="ts">
import { ElInput } from 'element-plus'
import { ContentWrap } from '@/components/ContentWrap'
import { inject, ref } from 'vue'

defineOptions({
  name: 'Menu7'
})

const axios = inject('$axios')
const text = ref('')
const keyword = ref('')
const ad = ref('')

const getAd = async () => {
  let word = text.value
  console.log(word)
  await axios
    .get('http://localhost:8080/xfxh/' + word, {
      keyword: word
    })
    .then((res) => {
      const da = res.data.data
      console.log(da)
      keyword.value = da.keyword
      ad.value = da.advertise
    })
    .catch((err) => {
      console.log(err)
    })
}
</script>

<template>
  <ContentWrap :title="'关键词广告文案生成'" class="pl-20px">
    <div class="container">
      <div class="bubble user" v-if="keyword !== ''">
        <div class="head"></div>
        <p class="message">
          {{ keyword }}
        </p>
      </div>
      <div class="bubble ai" v-if="ad !== ''">
        <div class="head"></div>
        <p class="message">
          {{ ad }}
        </p>
      </div>
    </div>
    <div class="flex items-center">
      <ElInput v-model="text" placeholder="Please input the keyword" />
      <el-button type="primary" @click="getAd">确认提交</el-button>
    </div>
  </ContentWrap>
</template>

<style>
.container {
  display: flex;
  height: 60vh;
  flex-direction: column;
}

.bubble {
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
}

.user {
  flex-direction: row-reverse;
  display: flex;
  justify-content: flex-start;
  align-items: flex-start;
  margin-right: 20px;
}

.user .head {
  width: 25px;
  height: 25px;
  margin-top: 25px;
  margin-left: 20px;
  background-color: green;
  border-radius: 50%;
}

.ai .head {
  width: 25px;
  height: 25px;
  margin-top: 25px;
  margin-right: 20px;
  background-color: red;
  border-radius: 50%;
}

.message {
  position: relative;
  max-width: 80%;
  padding: 10px 20px;
  border-radius: 5px;
}

.user .message {
  background-color: lightblue;
}

.ai .message {
  background-color: #f6f6f6;
}

.message::after {
  position: absolute;
  top: 10px;
  border: 10px solid transparent;
  content: '';
}

.ai .message::after {
  left: -20px;
  border-right-color: #f6f6f6;
}

.user .message::after {
  right: -20px;
  border-left-color: lightblue;
}
</style>
